<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
	<meta charset="utf-8">
	<title>登录--后台管理系统</title>
	<link rel="stylesheet" th:href="@{/css/layui/css/layui.css}"  />
	<link rel="stylesheet" th:href="@{/css/login.css}"  />
</head>
<body>
    <!--登录背景-->
	<div class="video_mask">
		<img src="/img/login_bg.jpg">
	</div>
	<div class="login">
	    <h1>登录</h1>
	    <div  id="form_add">
	    	<div class="layui-form-item">
				<input class="layui-input" name="userName" id="userName" placeholder="用户名" lay-verify="required" type="text">
		    </div>
		    <div class="layui-form-item">
				<input class="layui-input" name="passWord" id="passWord" placeholder="密码" lay-verify="required" type="password" >
		    </div>
			<button class="layui-btn login_btn submit_login" >登录</button>
			<label class="layui-form-label" style="color: white;font-size: 20px;width: 63%;padding-right: 20%;" id="login_msg"></label>
		</div>
	</div>
	<script th:src="@{/js/layui.all.js}"></script>
	<script th:src="@{/js/jquery.min.js}"></script>
	<script>
        $(".submit_login").click(function(){
            console.log($('#userName').val());
            //var username = $('#userName').val();
            //var password = $('#passWord').val();
            var username = "admin";
            var password = "123456";
            if(username.trim() == ""){
                $("#userName").css("border-color", "red");
                return;
			}
			if(password.trim() == ""){
                $("#passWord").css("border-color", "red");
                return;
			}
            json = {"userName": username, "passWord": password};

            //这里唯一需要注意的就是这个form-add的id
            $.ajax({
                url: '/user/login',
                type: 'POST',
                data:  JSON.stringify(json),
                contentType: 'application/json',
                dataType: "json",
                success: function (data) {
                    console.log(data);
                    //成功的回调
                    if(data.code == 0){
                        window.location.href = "/user/index";
                    }
                    else{
                        $('#login_msg').text(data.msg);
                    }

                },
                error: function (returndata) {
                    //请求异常的回调
                    // modals.warn("网络访问失败，请稍后重试!");
                }
            });
        });

	</script>
</body>
</html>
